package com.java.control.formvalidator;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;

import com.java.entity.QIndex;
import com.java.service.QuotationService;

/**
 * 
 * <p>供应信息验证类</p>
 *
 * 
 * @author $Author: develop $
 * @version $Revision: 1.13 ${Date}:Nov 26, 2008 4:30:21 PM $
 */
public class QIndexValidator extends BaseValidator  {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return QIndex.class.equals(clazz);
	}

	public void validate(Object obj, Errors errors) {
		QIndex offer =(QIndex)obj;
		
		//非空验证
		checkTextEmpty(errors, "qid", "产品名称");
		checkTextEmpty(errors, "qDate", "日期");
		
		String qid = offer.getQid();
		if(StringUtils.isNotBlank(qid)){
			Boolean bo = this.quotationService.existsQIndexByQId(offer.getId(),offer.getQid());
			if(bo){
				this.rejectValue(errors, "qid", "已有相同的报价单，请重新填写");
			}
		}
	}
	
	public void setQuotationService(QuotationService quotationService) {
		this.quotationService = quotationService;
	}

	private QuotationService quotationService;
}
